<?php
// +-------------------------------------------------------------------
// |
// +-------------------------------------------------------------------
// | Copyright (c) 2009-2016 All rights reserved.
// +-------------------------------------------------------------------
namespace Service\Api\V1;

class UserServiceOrderSub
{
    public $login = true; //是否需要登录才能访问该接口
    public $title = "预约提交ok";
    public $group = '物业服务';
    public $desc = "";

    public $input = [
        'service_id' => 'required;int;label=预约id',
        'remark' => 'label=备注',
        'contact' => 'required;label=联系人',
        'mobile' => 'required;label=联系方式',
        'address' => 'required;label=服务地址',
        'booking_time' => 'required;label=预约时间',
    ];

    public $output = [

    ];

    public function run($param, $uid)
    {
        $service = M('service')->where(['id' => $param['service_id']])->find();
        if(!$service) throw new \Exception('预约服务不存在');
        $list = M('service_order')
            ->add([
                'uid' => $uid,
                'service_id' => $param['service_id'],
                'remark' => $param['remark'],
                'contact' => $param['contact'],
                'mobile' => $param['mobile'],
                'address' => $param['address'],
                'booking_time' => $param['booking_time'],
            ]);
       if($list){
           return true;
       }else{
           throw new \Exception('提交失败');
       }
    }
}
